package main

import (
	"fmt"
	"runtime/debug"
)

func main() {
	defer fmt.Println("deferred call in main")
	firstName := "Elon"
	fullName(&firstName, nil)
	fmt.Println("returned normally from main")
}

func fullName(firstName *string, lastName *string) {
	//defer recover()
	defer reCTest()

	if firstName == nil {
		panic("runtime error: first name cannot be nil")
	}
	if lastName == nil {
		panic("runtime error: last name cannot be nil")
	}
	fmt.Printf("%s %s\n", *firstName, *lastName)
	fmt.Println("returned normally from fullName")
}

func reCTest() {
	//recover()

	if s := recover(); s != nil {
		fmt.Println("打印错误信息Err：", s)
		// 打印堆栈跟踪
		debug.PrintStack()
	}
}
